﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace GreateTool
{
    public partial class FileMoveForm : Form
    {
        public FileMoveForm()
        {
            InitializeComponent();
        }

        private void btnSourceFolder_Click(object sender, EventArgs e)
        {
            if (folderBrowserDialog1.ShowDialog() == DialogResult.OK) 
                tbSourceFolder.Text = folderBrowserDialog1.SelectedPath;
        }

        private void btnTargetFolder_Click(object sender, EventArgs e)
        {
            if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
                tbTargetFolder.Text = folderBrowserDialog1.SelectedPath;
        }

        private void btnCopyToTarget_Click(object sender, EventArgs e)
        {
            if (!Directory.Exists(tbSourceFolder.Text) || !Directory.Exists(tbTargetFolder.Text)) return;

            foreach (var str in tbSelectedFiles.Lines)
            {
                var str1 = str.Trim();
                
                if (str1.Length == 0) continue;

                var sourceFile = Path.Combine(tbSourceFolder.Text, str1);

                if (!File.Exists(sourceFile)) continue;

                var targetFile = Path.Combine(tbTargetFolder.Text, str1);

                File.Copy(sourceFile, targetFile,true);
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (!Directory.Exists(tbSourceFolder.Text) || !Directory.Exists(tbTargetFolder.Text)) return;

            foreach (var str in tbSelectedFiles.Lines)
            {
                var str1 = str.Trim();

                if (str1.Length == 0) continue;

                var sourceFile = Path.Combine(tbSourceFolder.Text, str1);

                if (!File.Exists(sourceFile)) continue;

                var targetFile = Path.Combine(tbTargetFolder.Text, str1);

                if (File.Exists(targetFile)) File.Delete(targetFile);

                File.Move(sourceFile, targetFile);
            }
        }
    }
}
